{% extends "base.html" %}
{% block base %}

<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
                    aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">陈勇志的接口测试平台</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav navbar-right">
                <li><a href="#">设置</a></li>
                <li><a href="/logout/">退出</a></li>
            </ul>
            <form class="navbar-form navbar-right">
                <input type="text" class="form-control" placeholder="搜索...">
            </form>
        </div>
    </div>
</nav>

<div class="container-fluid">
    <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
            <ul class="nav nav-sidebar">
                <li><a href="/project/"><i class="glyphicon glyphicon-th-large">&nbsp;</i>项目管理 <span class="sr-only">(current)</span></a></li>
                <li class="active"><a href="/module/"><i class="glyphicon glyphicon-th">&nbsp;</i>模块管理</a></li>
            </ul>
            <ul class="nav nav-sidebar">
                <li><a href="/case_manage/">用例管理</a></li>
                <li><a href="/task_manage/">任务管理</a></li>
            </ul>
            <ul class="nav nav-sidebar">
                <li><a href="">mock server</a></li>
                <li><a href="">测试工具</a></li>
                <li><a href="">更多工具</a></li>
            </ul>
        </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <!--模块列表-->
            {% if type == "list" %}
            <h4 class="sub-header">模块列表
                <button type="button" onclick="location.href='/module/add_module/'" class="btn btn-sm btn-primary"
                        style="float:right">新建
                </button>
            </h4>
            <div class="table-responsive">
                <table class="table table-striped">
                    <thead>
                    <tr>
                        <th>id</th>
                        <th>名称</th>
                        <th>描述</th>
                        <th>所属项目</th>
                        <th>创建时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for each_data in modules_data %}
                    <tr>
                        <td>{{ each_data.id }}</td>
                        <td>{{ each_data.name }}</td>
                        <td>{{ each_data.description }}</td>
                        <td>{{ each_data.project }}</td>
                        <td>{{ each_data.create_time | date:"Y-m-d H:i:s" }}</td>
                        <td>
                            <!--编辑按钮-->
                            <a href="/module/edit_module/{{ each_data.id }}/">
                                <i class="glyphicon glyphicon-pencil"></i>
                            </a>
                            <!--删除按钮-->
                            <a href="/module/del_module/{{ each_data.id }}/">
                                <i style="padding-left:5px;" class="glyphicon glyphicon-trash"></i>
                            </a>
                        </td>
                    </tr>
                    {% endfor %}
                   </tbody>
                </table>
            </div>
            {% endif %}
                    <!--添加模块-->
                    {% if type == "add" %}
                    <h4 class="page-header">新建模块</h4>
                    <form action="/module/add_module/" method="post">
                        <div class="form-group">
                            <label>所属项目</label>
                            {{ form.project }}
                        </div>
                        <div>
                            <label>模块名称</label>
                            <input type="text" name="input_module_name" class="form-control" id="input_module_name" style="width: 500px;" placeholder="请输入项目名称...">
                            <span style="color:red">{{ name_error }}</span>
                        </div>
                        <div class="form-group">
                            <label for="input_module_description">模块描述</label>
                            <textarea class="form-control" name="input_module_description" style="width: 500px;" rows="4"
                                      placeholder="请输入模块描述..."></textarea>
                        </div>
                        {% csrf_token %}
                        <button type="submit" class="btn btn-success">保存</button>
                    </form>
                    {% endif %}
<!--            编辑模块-->
            {% if type == "edit" %}
            <h4 class="page-header">编辑模块</h4>
            <form action="/module/edit_module/{{ id }}/" method="post">
                <p>{{ module_form.as_p }}</p>
                {% csrf_token %}
                <input class="btn btn-success" type="submit" value="保存">
            </form>
            {% endif %}
        </div>
    </div>

</div>

{% endblock %}
